package vsion.demo.service.safty.impl;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import vsion.demo.base.Curruser;
import vsion.demo.dao.safty.LoginDao;
import vsion.demo.dto.UserDto;
import vsion.demo.exception.BuesinessException;
import vsion.demo.exception.SysException;
import vsion.demo.model.SysUser;
import vsion.demo.service.safty.LoginService;

/**
 * @author Vsion
 * @date 2019/9/28 11:26
 */
@Service
@Transactional
public class LoginServiceImpl implements LoginService {
    @Autowired
    private LoginDao loginDao;
    @Override
    public Curruser checkLogin(UserDto dto) {
        SysUser user= null;
        try {
            user = loginDao.findUserByIdAndPwd(dto);
        } catch (Exception e) {
            throw new SysException("系统错误",e);
        }
        if (user==null) {
            throw new BuesinessException("账号或密码错误");
        }
        return new Curruser(user.getU_name(),user.getU_id());
    }
}
